/*
 *	Copyright © 2013 Changsha Shishuo Network Technology Co., Ltd. All rights reserved.
 *	长沙市师说网络科技有限公司 版权所有
 *	http://www.shishuo.com
 */

package com.hlingsoft.kkh.action.admin;

import com.hlingsoft.kkh.entity.AppUser;
import com.hlingsoft.kkh.entity.vo.PageVo;
import com.hlingsoft.kkh.exception.FolderNotFoundException;
import com.hlingsoft.kkh.util.Common;
import com.hlingsoft.kkh.util.HttpUtils;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * @author lqq
 * @author 进入网站后台首页
 * 
 */

@Controller
@RequestMapping("/admin")
public class AdminAction extends AdminBaseAction {

//	@RequestMapping(value = "/index.htm", method = RequestMethod.GET)
//	public String allList(
//			@RequestParam(value = "p", defaultValue = "1") int pageNum,
//			HttpServletRequest request,
//			ModelMap modelMap) {
//		PageVo<AppUser> pageVo = new PageVo<AppUser>(pageNum);
//		pageVo.setRows(10);
//		pageVo.basePath= HttpUtils.getBasePath(request)+"/admin/appUser/list.htm" ;
//		List<AppUser> appUserList = userDao.getAppUserWithNone(pageVo.getOffset(), pageVo.getRows());
//		for (AppUser appUser:appUserList){
//			String interests="";
//			appUser.setProfession(professionDao.getProfessionById(appUser.getProfessionId()).getName());
//			String interestIds = appUser.getInterestIds();
//			List<Integer> integerList = Common.strToIntegerList(interestIds);
//			for (Integer interestId:integerList){
//				String interest  = interestDao.getInterestById(interestId).getName();
//				interests += interest+",";
//			}
//			if (interestIds.length()>0){
//				interests=interests.substring(0, interests.length() - 1);
//			}
//			appUser.setInterests(interests);
//		}
//		pageVo.setList(appUserList);
//		pageVo.setCount(userDao.getAppUserWithNoneCount());
//
//		modelMap.put("professionList",professionDao.getProfession());
//		modelMap.put("interestList",interestDao.getInterest());
//		modelMap.put("p", pageNum);
//		modelMap.put("pageVo", pageVo);
//		return "system/appUser/list";
//	}


	@RequestMapping(value = "/index.htm")
	public String allList(
			HttpServletRequest request,
			ModelMap modelMap) {
//		List<AppUser> appUserList = userDao.getAppUserWithNone1();
		List<AppUser> appUserList = userDao.getAppUserWithNone(0,10);
		for (AppUser appUser : appUserList) {
			String interests = "";
			appUser.setProfession(professionDao.getProfessionById(appUser.getProfessionId()).getName());
			String interestIds = appUser.getInterestIds();
			List<Integer> integerList = Common.strToIntegerList(interestIds);
			for (Integer interestId : integerList) {
				String interest = interestDao.getInterestById(interestId).getName();
				interests += interest + ",";
			}
			if (interests.length() > 0) {
				interests = interests.substring(0, interests.length() - 1);
			}
			appUser.setInterests(interests);
		}

		modelMap.put("appUserList", appUserList);
		return "system/appUser/list";
	}
}
